package bookless.pakage;

import java.util.ArrayList;

public class BookHandler {

	public BookHandler() {

	}

	/**
	 * This method checks the input so it's correct, if input is correct it
	 * stores the book in the database.
	 * 
	 * @return String, tells if the book was stored or not
	 */
	public static String addBook(String title, String author, String sPrice,
			String comments) {
		String response = null;

		int price = Integer.parseInt(sPrice);

		if (title.isEmpty() || author.isEmpty() || price < 0
				|| comments.isEmpty()) {
			response = "noInPut";
			return response;
		} else {
			StorageHandler.storeBook(new Book(title, author, sPrice, comments));
			if (StorageHandler.didStoringBookWork) {
				response = "ok";
			} else {
				response = "didntWork";
			}
			return response;
		}
	}

	/**
	 * Removes a book with the title send in
	 * 
	 * @param title name of the book that will be removed
	 */
	public static void removeBook(String title) {

		StorageHandler.removeBook(UserHandler.session, title);
	}

	/**
	 * Not implemented
	 * @param book
	 */
	public static void editBook(Book book) {

	}

	/**
	 * Return a list with all books from the database written by the author
	 * @param author the author's books wanted
	 * @return ArrayList with books.
	 */
	public static ArrayList<Book> getBooksByAuthor(String author) {

		ArrayList<Book> list = new ArrayList<Book>();

		list = StorageHandler.getBooksByAuthor(author);

		return list;
	}

	/**
	 * Return a list with all books from the database with the title
	 * @param title the title on the books on the list
	 * @return ArrayList with books
	 */
	public static ArrayList<Book> getBooksByTitle(String title) {

		ArrayList<Book> list = new ArrayList<Book>();
		list = StorageHandler.getBooksByTitle(title);

		return list;
	}

	/**
	 * Return a list with all the books in the database
	 * @return ArrayList with books
	 */
	public static ArrayList<Book> getAllBooks() {

		ArrayList<Book> list = new ArrayList<Book>();
		list = StorageHandler.getAllBooks();

		return list;
	}
}
